package lg.minecraft.plugin.cobblemoncore.config.mapping;

import com.cobblemon.mod.common.api.pokemon.Natures;
import com.cobblemon.mod.common.pokemon.Nature;
import lg.minecraft.plugin.cobblemoncore.LGCobblemonCore;
import lg.minecraft.plugin.cobblemoncore.util.LocalizedName;
import lombok.Getter;

/**
 * @author langle__
 * @version 1.0
 */
@Getter
public class NatureMapping extends AbstractMapping<Nature> {

    public NatureMapping() {
        super(LGCobblemonCore.getInstance(), "nature.yml", LGCobblemonCore.getMappingDirectory().getPath());
    }

    @Override
    protected boolean isUseLocalFile() {
        return LGCobblemonCore.getMainConfig().isNature();
    }

    @Override
    protected void loadFromDynamicSource() {
        for (String key : getKeys(false)) {
            String value = getString(key);
            Nature nature = Natures.INSTANCE.getNature(key);
            if (nature == null) {
                getPlugin().getLogger().warning("Nature " + key + " not found!");
                continue;
            }
            mapping.put(value, nature);
            reverse.put(nature, value);
        }
    }

    @Override
    protected void loadFromLocalFile() {
        for (Nature nature : Natures.INSTANCE.all()) {
            String displayName = LocalizedName.getNatureName(nature);
            mapping.put(displayName, nature);
            reverse.put(nature, displayName);
        }
    }

}
